package utils 


func WrapPacket[T ~[]byte](fields ...T) (out []byte) {
	for _, f := range fields {
		out = append(out, f...)
	}
	return
}

// 加载数据包字段值
func LoadPacket[T ~[]byte](data []byte, fields ...T) error {
	startIndex := 0
	endIndex := 0
	for i, f := range fields {
		startIndex = endIndex
		endIndex = len(f) + startIndex
		if len(f) == 0 {
			if i != len(fields)-1 {
				return &ErrFieldSort{}
			}
			copy(f, data[endIndex:])

		} else {
			copy(f, data[startIndex:endIndex])
		}
	}

	return nil
}